//
//  ViewController.m
//  3DTouchDemo
//
//  Created by 博广 on 2016/11/11.
//  Copyright © 2016年 博广. All rights reserved.
//

#import "MainViewController.h"
#import "HomeViewController.h"

@interface MainViewController ()<UIViewControllerPreviewingDelegate>

@end

@implementation MainViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.title = @"首页";
    
    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"jt"]];;
    imageView.frame = CGRectMake(0, 0, 200, 200);
    imageView.center = self.view.center;
    imageView.userInteractionEnabled = YES;
    imageView.contentMode = UIViewContentModeScaleAspectFit;
    [self.view addSubview:imageView];
    
    if (self.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable) {
        NSLog(@"3d touch 可用");
    }
    
    #ifdef __IPHONE_9_0
    [self registerForPreviewingWithDelegate:self sourceView:imageView];
    #endif
}

-(void)previewingContext:(id<UIViewControllerPreviewing>)previewingContext commitViewController:(UIViewController *)viewControllerToCommit
{
    NSLog(@"%s",__func__);
//    [self.navigationController pushViewController:[[HomeViewController alloc] init] animated:YES];
    [self showViewController:[[HomeViewController alloc] init] sender:self];
}

- (UIViewController *)previewingContext:(id<UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location
{
    NSLog(@"%s,%@",__func__,NSStringFromCGPoint(location));
    HomeViewController *vc = [[HomeViewController alloc] init];
    //调整大小
    vc.preferredContentSize = CGSizeMake(300, 200);
    return vc;
}

@end
